package com.binvshe.binvshe.mine.corporation.model;

import android.text.TextUtils;

import com.binvshe.binvshe.app.MyApplication;
import com.google.gson.annotations.SerializedName;
import com.pachong.android.frameworkbase.utils.io.SharePreferenceUtil;

/**
 * FileName: MyClubBean
 *
 * @CretedBy : zofnk
 * @CreateDate: 2016/9/13 14:02
 * @E-mail: zofnk@vip.qq.com
 * @RevisionsDate：
 * @ModifyNotes：
 */
public class MyClubBean {

    /**
     * id : 106
     * user_id : 215
     * name : 12
     * catid : 0
     * portrait : http://static.binvshe.com/static/crawler/1473322637028641.png
     * sign : null
     * introduction : null
     * province : 北京
     * city : 房山
     * longitude : 0
     * latitude : 0
     * name_py : 12
     * initial : #
     * state : true
     * del : false
     * create_time : 2016-09-08T16:17:29.000+0800
     * update_time : 2016-09-08T16:17:29.000+0800
     * cate_name : null
     */

    private static final String SP_FILENAME_ACCOUNT = MyClubBean.class.getSimpleName();
    private static final String KEY_ID = "id";
    private static final String KEY_USER_ID = "user_id";
    private static final String KEY_NAME = "name";
    private static final String KEY_CATID = "catid";
    private static final String KEY_PORTRAIT = "portrait";
    private static final String KEY_SIGN = "sign";
    private static final String KEY_INTRODUCTION = "introduction";
    private static final String KEY_PROVINCE = "province";
    private static final String KEY_CITY = "city";
    private static final String KEY_LONGITUDE = "longitude";
    private static final String KEY_LATITUDE = "latitude";
    private static final String KEY_NAME_PY = "name_py";
    private static final String KEY_INITIAL = "initial";
    private static final String KEY_STATE = "state";
    private static final String KEY_DEL = "del";
    private static final String KEY_CREATE_TIME = "create_time";
    private static final String KEY_UPDATE_TIME = "update_time";
    private static final String KEY_CATE_NAME = "cate_name";

    private static MyClubBean mMyClubBean;


    @SerializedName("id")
    private String mId;

    @SerializedName("user_id")
    private String mUserId;

    @SerializedName("name")
    private String mName;

    @SerializedName("catid")
    private String mCatid;

    @SerializedName("portrait")
    private String mPortrait;

    @SerializedName("sign")
    private String mSign;

    @SerializedName("introduction")
    private String mIntroduction;

    @SerializedName("province")
    private String mProvince;

    @SerializedName("city")
    private String mCity;

    @SerializedName("longitude")
    private String mLongitude;

    @SerializedName("latitude")
    private String mLatitude;

    @SerializedName("name_py")
    private String mName_py;

    @SerializedName("initial")
    private String mInitial;

    @SerializedName("state")
    private boolean mState;

    @SerializedName("del")
    private boolean mDel;

    @SerializedName("create_time")
    private String mCreate_time;

    @SerializedName("update_time")
    private String mUpdate_time;

    @SerializedName("cate_name")
    private String mCate_name;


    public static MyClubBean createFromSp() {
        MyClubBean clubBean = new MyClubBean();
        clubBean.setId(getString(KEY_ID));
        clubBean.setUser_id(getString(KEY_USER_ID));
        clubBean.setName(getString(KEY_NAME));
        clubBean.setCatid(getString(KEY_CATE_NAME));
        clubBean.setPortrait(getString(KEY_PORTRAIT));
        clubBean.setSign(getString(KEY_SIGN));
        clubBean.setIntroduction(getString(KEY_INTRODUCTION));
        clubBean.setProvince(getString(KEY_PROVINCE));
        clubBean.setCity(getString(KEY_CITY));
        clubBean.setLongitude(getString(KEY_LONGITUDE));
        clubBean.setLatitude(getString(KEY_LATITUDE));
        clubBean.setName_py(getString(KEY_NAME_PY));
        clubBean.setInitial(getString(KEY_INITIAL));
        clubBean.setState(getBoolean(KEY_STATE));
        clubBean.setDel(getBoolean(KEY_DEL));
        clubBean.setCreate_time(getString(KEY_CREATE_TIME));
        clubBean.setUpdate_time(getString(KEY_UPDATE_TIME));
        clubBean.setCate_name(getString(KEY_CATE_NAME));
        return clubBean;
    }

    public static MyClubBean createFrom(MyClubBean acct) {
        MyClubBean club = new MyClubBean();
        club.setId(club.getId());
        club.setUser_id(club.getUser_id());
        club.setName(club.getName());
        club.setCatid(club.getCatid());
        club.setPortrait(club.getPortrait());
        club.setSign(club.getSign());
        club.setIntroduction(club.getIntroduction());
        club.setProvince(club.getProvince());
        club.setCity(club.getCity());
        club.setLongitude(club.getLongitude());
        club.setLatitude(club.getLatitude());
        club.setName_py(club.getName_py());
        club.setInitial(club.getInitial());
        club.setState(club.getState());
        club.setDel(club.getDel());
        club.setCreate_time(club.getCreate_time());
        club.setUpdate_time(club.getUpdate_time());
        club.setCate_name(club.getCate_name());
        return club;
    }

    public static MyClubBean getCurrentClub() {
        if (mMyClubBean == null) {
            mMyClubBean = createFromSp();
        }
        return mMyClubBean;
    }

    public static void setCurrentClubBean(MyClubBean myClubBean) {
        mMyClubBean = createFrom(myClubBean);
    }

    public String getId() {
        return mId;
    }

    public void setId(String id) {
        if (!TextUtils.equals(this.mId, id)) {
            mId = id;
            saveString(KEY_ID, mId);
        }
    }

    public String getUser_id() {
        return mUserId;
    }

    public void setUser_id(String user_id) {
        if (!TextUtils.equals(mUserId, user_id)) {
            mUserId = user_id;
            saveString(KEY_USER_ID, mUserId);
        }
    }

    public String getName() {
        return mName;
    }

    public void setName(String name) {
        if (!TextUtils.equals(mName, name)) {
            mName = name;
            saveString(KEY_NAME, mName);
        }
    }

    public String getCatid() {
        return mCatid;
    }

    public void setCatid(String catid) {
        if (!TextUtils.equals(mCatid, catid)) {
            mCatid = catid;
            saveString(KEY_CATID, mCatid);
        }
    }

    public String getPortrait() {
        return mPortrait;
    }

    public void setPortrait(String portrait) {
        if (!TextUtils.equals(mPortrait, portrait)) {
            mPortrait = portrait;
            saveString(KEY_PORTRAIT, mPortrait);
        }
    }

    public String getSign() {
        return mSign;
    }

    public void setSign(String sign) {
        if (!TextUtils.equals(mSign, sign)) {
            mSign = sign;
            saveString(KEY_SIGN, mSign);
        }
    }

    public String getIntroduction() {
        return mIntroduction;
    }

    public void setIntroduction(String introduction) {
        if (!TextUtils.equals(mIntroduction, introduction)) {
            mIntroduction = introduction;
            saveString(KEY_INTRODUCTION, mIntroduction);
        }
    }

    public String getProvince() {
        return mProvince;
    }

    public void setProvince(String province) {
        if (!TextUtils.equals(mProvince, province)) {
            mProvince = province;
            saveString(KEY_PROVINCE, mProvince);
        }
    }

    public String getCity() {
        return mCity;
    }

    public void setCity(String city) {
        if (!TextUtils.equals(mCity, city)) {
            mCity = city;
            saveString(KEY_CITY, mCity);
        }
    }

    public String getLongitude() {
        return mLongitude;
    }

    public void setLongitude(String longitude) {
        if (!TextUtils.equals(mLongitude, longitude)) {
            mLongitude = longitude;
            saveString(KEY_LONGITUDE, mLongitude);
        }
    }

    public String getLatitude() {
        return mLatitude;
    }

    public void setLatitude(String latitude) {
        if (!TextUtils.equals(mLatitude, latitude)) {
            mLatitude = latitude;
            saveString(KEY_LATITUDE, mLatitude);
        }
    }

    public String getName_py() {
        return mName_py;
    }

    public void setName_py(String name_py) {
        if (!TextUtils.equals(mName_py, name_py)) {
            mName_py = name_py;
            saveString(KEY_NAME_PY, mName_py);
        }
    }

    public String getInitial() {
        return mInitial;
    }

    public void setInitial(String initial) {
        if (!TextUtils.equals(mInitial, initial)) {
            mInitial = initial;
            saveString(KEY_INITIAL, mInitial);
        }
    }

    public boolean getState() {
        return mState;
    }

    public void setState(boolean state) {
        if (!(mState == state)) {
            mState = state;
            saveBoolean(KEY_STATE, mState);
        }
    }

    public boolean getDel() {
        return mDel;
    }

    public void setDel(boolean del) {
        if (!(mDel == del)) {
            mDel = del;
            saveBoolean(KEY_DEL, mDel);
        }
    }

    public String getCreate_time() {
        return mCreate_time;
    }

    public void setCreate_time(String create_time) {
        if (!TextUtils.equals(mCreate_time, create_time)) {
            mCreate_time = create_time;
            saveString(KEY_CREATE_TIME, mCreate_time);
        }
    }

    public String getUpdate_time() {
        return mUpdate_time;
    }

    public void setUpdate_time(String update_time) {
        if (!TextUtils.equals(mUpdate_time, update_time)) {
            mUpdate_time = update_time;
            saveString(KEY_UPDATE_TIME, mUpdate_time);
        }
    }

    public String getCate_name() {
        return mCate_name;
    }

    public void setCate_name(String cate_name) {
        if (!TextUtils.equals(mCate_name, cate_name)) {
            mCate_name = cate_name;
            saveString(KEY_CREATE_TIME, mCate_name);
        }
    }

    private static void saveInt(String key, int value) {
        SharePreferenceUtil.saveInt(MyApplication.getAppContext(), SP_FILENAME_ACCOUNT, key, value);
    }

    private static int getInt(String key) {
        return SharePreferenceUtil.getInt(MyApplication.getAppContext(), SP_FILENAME_ACCOUNT, key);
    }

    private static void saveString(String key, String value) {
        SharePreferenceUtil.saveString(MyApplication.getAppContext(), SP_FILENAME_ACCOUNT, key, value);
    }

    private static String getString(String key) {
        return SharePreferenceUtil.getString(MyApplication.getAppContext(), SP_FILENAME_ACCOUNT, key);
    }

    private static void saveBoolean(String key, Boolean value) {
        SharePreferenceUtil.saveBoolean(MyApplication.getAppContext(), SP_FILENAME_ACCOUNT, key, value);
    }

    private static Boolean getBoolean(String key) {
        return SharePreferenceUtil.getBoolean(MyApplication.getAppContext(), SP_FILENAME_ACCOUNT, key, false);
    }
}
